package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import java.util.ArrayList;
import control.*;
import model.*;

public class ProductTable extends JFrame
{
	private JPanel contentPane;
	private JTable table;
	private ProductCtrl proCtrl = new ProductCtrl();
	private static ProductTableList pList;

	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					ProductTable frame = new ProductTable();
					frame.setVisible(true);
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}
	
	public ProductTable()
	{
		setTitle("List Of All Products");
		pList = new ProductTableList();
		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 800, 500);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 11, 764, 440);
		contentPane.add(scrollPane);
		
		table = new JTable();
		
		table.setModel(new javax.swing.table.DefaultTableModel(
	            new Object [][]{},
	            new String []
	            {
	            		"ID", "Name", "Purchase Price", "Sales Price", "Rent Price", "Country", "Min Stock", "Supplier ID", "Product Type"
	            })
				{
	            Class[] types = new Class []
	            {
	                java.lang.Integer.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class
	            };

	            public Class getColumnClass(int columnIndex)
	            {
	                return types [columnIndex];
	            }
				});
		scrollPane.setViewportView(table);
				}
	
	public void updateProductTable()
	{
        pList.setP(proCtrl.getAllProducts());
        table.setModel(pList);
        table.setAutoCreateRowSorter(true);
	}
}
